global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

set scheme plotplain
graph set window fontface "Times New Roman"

capture log close

log using "$log/18_worker_separation_table_figures", replace

**************************************
*Output Table
**************************************
cap program drop save_est
program define save_est 
args name start

	*Save estimates
	use  "$output/`name'.dta", clear
	
	local index = `start'
	forvalues i=1/2 {
		preserve 
		keep if _n==`i'
		
		*Regression Coefficients
		sum beta1
		global b`index'_t0=round(r(mean), 0.0001)
		sum se1 
		global se`index'_t0=round(r(mean),0.0001)
		sum beta2
		global b`index'_t1=round(r(mean), 0.0001)
		sum se2 
		global se`index'_t1=round(r(mean),0.0001)
		sum beta3
		global b`index'_t2=round(r(mean), 0.0001)
		sum se3 
		global se`index'_t2=round(r(mean),0.0001)
		sum beta_change
		global b`index'_change=round(r(mean), 0.0001)
		sum se_change
		global se`index'_change=round(r(mean),0.0001)
		
		*Baseline characteristics
		sum n
		global n`index'=string(r(mean), "%10.0fc")
		
		restore 
		local ++index
	}
	
	sum beta_change if _n==3 
	global baseline`start'=round((1-r(mean))/7, 0.0001)
end 


*Table Ic
save_est employed_table_estimates_year 1

	capture erase "$tables/table3_year.tex"
	file open fh3 using "$tables/table3_year.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc }" _n ///
		"\toprule" _n ///
		"&& (1) && (2) \\" _n ///
		"\midrule" _n ///
		"Pre-trend && $b1_t0 && $b2_t0   \\" _n ///
		" && ($se1_t0) && ($se2_t0) \\" _n ///
		"[1em] \\" _n ///
		"Anticipation && $b1_t1 && $b2_t1 \\" _n ///
		" && ($se1_t1) && ($se2_t1)  \\" _n ///
		"[1em] \\" _n ///
		"Post-trend && $b1_t2 && $b2_t2   \\" _n ///
		" && ($se1_t2) && ($se2_t2) \\" _n ///
		"[1em] \\" _n ///
		"Change in Slope && $b1_change && $b2_change  \\" _n ///
		" && ($se1_change) && ($se2_change) \\" _n ///
		"\midrule" _n ///
		"Baseline Monthly Separations && $baseline1 && $baseline1 \\" _n ///
		"Worker FE 		  && Y && Y   \\" _n ///
		"Month FE 		  && Y && -  \\" _n ///
		"Firm-Month FE 	  && - && Y  \\" _n ///
		"N && $n1 && $n2  \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 
	
*Table Ib
save_est employed_table_estimates 1
save_est employed_table_estimates_year 3

	capture erase "$tables/table3b_year.tex"
	file open fh3 using "$tables/table3b_year.tex", write replace

	file write fh3 ///
		"\begin{tabular}{@{\hskip\tabcolsep\extracolsep\fill} l cc cc cc cc }" _n ///
		"\toprule" _n ///
		"&& (1) && (2) && (3) && (4) \\" _n ///
		"\midrule" _n ///
		"Pre-trend && $b1_t0 && $b2_t0 && $b3_t0 && $b4_t0   \\" _n ///
		" && ($se1_t0) && ($se2_t0) && ($se3_t0) && ($se4_t0) \\" _n ///
		"[1em] \\" _n ///
		"Anticipation && $b1_t1 && $b2_t1 && $b3_t1 && $b4_t1 \\" _n ///
		" && ($se1_t1) && ($se2_t1) && ($se3_t1) && ($se4_t1)  \\" _n ///
		"[1em] \\" _n ///
		"Post-trend && $b1_t2 && $b2_t2 && $b3_t2 && $b4_t2   \\" _n ///
		" && ($se1_t2) && ($se2_t2) && ($se3_t2) && ($se4_t2) \\" _n ///
		"[1em] \\" _n ///
		"Change in Slope && $b1_change && $b2_change && $b3_change && $b4_change  \\" _n ///
		" && ($se1_change) && ($se2_change)  && ($se3_change) && ($se4_change) \\" _n ///
		"\midrule" _n ///
		"Baseline Monthly Separations && $baseline1 && $baseline1 && $baseline3 && $baseline3 \\" _n ///
		"Worker FE 		  && Y && Y && Y && Y   \\" _n ///
		"Month FE 		  && Y && - && Y && -  \\" _n ///
		"Firm-Month FE 	  && - && Y && - && Y  \\" _n ///
		"N && $n1 && $n2 && $n3 && $n4 \\" _n ///
		"\bottomrule" _n ///
		"\end{tabular}" _n
		
	file close fh3 
	macro drop fh3 

log close
